package com.ido.otaclient;


import android.content.Context;

import com.ido.otaclient.base.BasePreference;
import com.ido.otaclient.env.AppEnv;
import com.ido.otaclient.module.UploadConfig;

/**
 * Copyright (c) 2019 深圳市爱都科技有限公司. All rights reserved.
 *
 * @Author: xyb
 * @CreateDate: 2020-02-17 20:18
 * @description
 */
public class UploadConfigPreference extends BasePreference {
    private static final String NAME = "upload_preference";

    private static final String TASK_NAME = "taskName";
    /**
     * 升级配置
     */
    private UploadConfig mUploadConfig;

    private static volatile UploadConfigPreference instance;

    private static Context getContext() {
        return AppEnv.instance().getContext();
    }

    public static UploadConfigPreference getInstance() {
        if (instance == null) {
            synchronized (UploadConfigPreference.class) {
                if (instance == null) {
                    instance = new UploadConfigPreference();
                }
            }
        }
        return instance;
    }

    /**
     * 保存配置在本地
     * @param uploadConfig
     */
    public void saveUploadConfig(UploadConfig uploadConfig){
        if(uploadConfig == null){
            uploadConfig = new UploadConfig();
        }
        saveString(getContext(),NAME,TASK_NAME,uploadConfig.getTaskName());
        mUploadConfig = uploadConfig;
    }

    /**
     * 从本地取出数据
     * @return
     */
    public UploadConfig getUploadConfig(){
        mUploadConfig = new UploadConfig();
        mUploadConfig.setTaskName(getString(getContext(),NAME,TASK_NAME));
        return mUploadConfig;
    }
}
